<?php
/*
Copyright (C) 2009 de Flotte Maxence

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
?>
<?php
class Bout {
  protected $name;
  protected $inner;
  protected $_arg = null;
  protected $_Flux;
  protected $bootName;
  protected $url;
  private $_autoSet;

  //Constructeur
  public function __construct($name) {
    $this->name = $name;
  }
  //Ajout du résultat d'un objet à une propriété
  public function sendObjBuiltIntoInner($Inner) {
    $this->inner .= $Inner."\n";
  }
  public function setInner($inner) {
    $this->inner = $inner;
  }
  //Ajout d'un flux
  public function addFlux($Flux, $Type) {
    $this->_Flux[] = array('flux' => $Flux,'type' => $Type);
  }
  //Ajout d'un objet dans une propriété
  public function AddObject2($Var,$Obj) {
    if ($this->_Object[$Var] == NULL)
      $this->_Object[$Var][] = $Obj; 
    if(!in_array($Obj,$this->_Object[$Var]))
      $this->_Object[$Var][] = $Obj;
  }
  //NoCache
  protected function reportError($msg = null) {
    if($this->page != null)
      $this->page->noCache = true;
    $file = fopen('./Log/errors.log','a+');
    fwrite($file,date('d/m/Y H/i/s').' : '.$_SERVER['REQUEST_URI'].' : '.$_SERVER['HTTP_REFERER'].' : '.$msg."\n");
    fclose($file);
  }

  //Me :: permet de rendre dynamique un objet
  function Me() {

    if(isSet($this->_autoSet))
      foreach($this->_autoSet as $arg) {
	$autoSet .= '  $'.$this->name.'->set'.$arg.'(\''.$this->$arg.'\')'.";\n";
      }
    else
      $autoSet = null;

    return "
<?php
  $$this->name = new $this->bootName('$this->name');
  $$this->name->setInner('".$this->inner."');
$autoSet
  echo $$this->name->build();
?>";

  }

  //AutoSet
  function addAutoSet($arg) {
    $this->_autoSet[] = $arg;
  }
}